Page({
  fromType: null, // 页面来源
  onLoad(e) {
    e.type ? (this.fromType = e.type, this.setData({
      fromType: e.type
    }), wx.setNavigationBarTitle({
      title: '我收藏的' + (e.type == 'song' ? '歌单' : e.type == 'singer' ? '歌手' : e.type == 'bang' ? '榜单' : ''),
    })) : null
    let songList = []
    switch (this.fromType) {
      case "song":
        songList = wx.getStorageSync('collectionSong') || []
        break;
      case "bang":
        songList = wx.getStorageSync('collectionBang') || []
        break;
      case "singer":
        songList = wx.getStorageSync('collectionSinger') || []
        break;
      default:
        songList = []
        break;
    }
    this.setData({
      songList
    })
  },
  // 取消收藏
  async calcelCollection(e) {
    let {
      id
    } = e.currentTarget.dataset
    let songList = this.data.songList.filter(item => item.listId && item.listId != id || item.singerId && item.singerId != id || item.bangId && item.bangId != id)
    this.setData({
      songList
    })
    wx.setStorage({
      key: this.fromType == "song" ? "collectionSong" : this.fromType == "bang" ? "collectionBang" : this.fromType == "singer" ? "collectionSinger" : null,
      data: songList,
      success: () => {
        wx.showToast({
          title: '已取消收藏',
          icon: 'none'
        })
      }
    })
  },
  toListPage(e) {
    let {
      id,
      title
    } = e.currentTarget.dataset
    wx.navigateTo({
      url: `/pages/music/index?type=${this.fromType}&id=${id}&navtitle=${title}`,
    })
  },
})